<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="html" encoding="iso-8859-1" omit-xml-declaration="yes" />


	<!-- XSL PARAMETERS-->
	<xsl:param name="previous" />
	<xsl:param name="perPage" select="25" />
	<xsl:param name="next" />
	<xsl:param name="current" select="(queryResult/results/page)+1" />
	<xsl:param name="total" select="queryResult/results/totalPages" />



	<!--XSL VARIABLE DECLARTIONS

The following code keeps track of the variable pointer to start -->
	<xsl:variable name="registry" select='"4444/registry"' />

	<xsl:variable name="pstart">
		<xsl:choose>
			<xsl:when test="($current mod 5) = 0">
				<xsl:value-of select="$current - 4" />
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$current - ($current mod 5) + 1" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>

	<xsl:variable name="lastEntryNum" select="((queryResult/results/page+1)*25)"/>
	<xsl:variable name="firstEntryNum" select="(($lastEntryNum)-24)"/>
	<xsl:variable name="lastEntryMaxVal" select="queryResult/results/nhits"/>
	<xsl:variable name="lastPageResults" select="(($lastEntryMaxVal)-($firstEntryNum))"/>
	<xsl:variable name="queryName" select="queryResult/results/queryString"/>



	<!--1. DISPLAYHEADER TEMPLATE DECLARATION*******************************-->
	<xsl:template name="displayHeader">
		<h2 id="h2_search_results">Search Results</h2>

		<p id="search_result_for">
			Results for "<xsl:value-of select="queryResult/results/queryString"/>"
		</p>

		<p id="search_result_count">
			Showing
			<xsl:choose>
				<xsl:when test="$lastEntryNum > $lastEntryMaxVal">
					<font style="font-weight:bold">
						<xsl:value-of select="$firstEntryNum" /> -
						<xsl:value-of select="$lastEntryMaxVal" />
					</font>
					&#160;of&#160;
					<font style="font-weight:bold">
						<xsl:value-of select="queryResult/results/nhits"/>
					</font>
				</xsl:when>
				<xsl:otherwise>
					<font style="font-weight:bold">
						<xsl:value-of select="$firstEntryNum"/> - <xsl:value-of select="$lastEntryNum"/>
					</font>
					&#160;of&#160;
					<font style="font-weight:bold">
						<xsl:value-of select="queryResult/results/nhits"/>
						&#160;results
					</font>
				</xsl:otherwise>
			</xsl:choose>
		</p>
	</xsl:template>
	<!--**********************************************************************-->








	<!--2. PAGING TEMPLATE DECLARATION*****************************************-->
	<xsl:template name="paging">

		<!-- accept parameters here -->
		<xsl:param name="perPage" />
		<xsl:param name="counter" />
		<xsl:param name="current" />
		<xsl:param name="total" />


		<xsl:choose>
			<!-- makes the current page number appear in bold text-->

			<xsl:when test="$pstart=$total">
				<span style="color: black">
					<strong>
						<xsl:value-of select="$current" />
					</strong>&#160;
				</span>
			</xsl:when>

			<xsl:when test="$counter = $current and ($current != ($pstart + 4))">
				<span style="color: black">
					<strong>
						<xsl:value-of select="$current" />,
					</strong>
				</span>
			</xsl:when>

			<xsl:when test="$counter = $current and ($current = ($pstart + 4))">
				<span style="color: black">
					<strong>
						<xsl:value-of select="$current" />
					</strong>&#160;
				</span>
			</xsl:when>

			<xsl:when test="($counter mod 5) = 0">
				<a href='/search/results.jsp?textsearch={$queryName}&amp;registry={$registry}&amp;page={($counter - 1)}'>
					<xsl:value-of select="$counter" />
				</a>&#160;
			</xsl:when>

			<xsl:otherwise>
				<a href='/training/search/results.jsp?textsearch={$queryName}&amp;registry={$registry}&amp;page={($counter - 1)}'>
					<xsl:value-of select="$counter" />
				</a>,
			</xsl:otherwise>
		</xsl:choose>



		<xsl:if test="$counter &lt; $total">
			<!--Recursive Call to template "paging" -->
			<xsl:call-template name="paging">
				<xsl:with-param name="perPage" select="$perPage" />
				<xsl:with-param name="counter" select="$counter + 1" />
				<xsl:with-param name="current" select="$current" />
				<xsl:with-param name="total" select="$total" />
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
	<!--*******************************************************************-->









	<!--3. DISPLAYPAGINGSTRUCT TEMPLATE DECLARATION*******************************-->
	<xsl:template name="displayPagingStruct">


		<!-- determine if the previous links should be displayed -->
		<xsl:if test="$current &gt; 5">
			<xsl:variable name="prevEllipsesPageNo" select="$pstart - 1" />

			<a href='/training/search/results.jsp?textsearch={$queryName}&amp;registry={$registry}&amp;page={($prevEllipsesPageNo - 1)}'>
				<img border="0" src="/_styles/skin/search_results_prev.gif"/>
			</a>&#160;
		</xsl:if>

		<xsl:if test="$current != 1">
			<a href='/training/search/results.jsp?textsearch={$queryName}&amp;registry={$registry}&amp;page={($current - 2)}'>Previous</a>&#160;
		</xsl:if>


		<!--CONTROLS CALLS MADE TO THE PAGING TEMPLATE-->
		<xsl:choose>
			<xsl:when test="$total &gt; ($pstart + 4)">

				<xsl:variable name="pend" select="$pstart + 4" />

				<!-- CALL PAGING TEMPLATE -->
				<xsl:call-template name="paging">

					<!-- pass the following parameters: -->
					<xsl:with-param name="perPage" select="$perPage" />
					<xsl:with-param name="counter" select="$pstart" />
					<xsl:with-param name="current" select="$current" />
					<xsl:with-param name="total" select="$pend" />
				</xsl:call-template>

				<xsl:variable name="nextEllipsesPageNo" select="$pend + 1" />


				<xsl:if test="$current != $total">
					<a href='/training/search/results.jsp?textsearch={$queryName}&amp;registry={$registry}&amp;page={$current + 1}'>NEXT</a>&#160;

					<a href='/training/search/results.jsp?textsearch={$queryName}&amp;registry={$registry}&amp;page={$nextEllipsesPageNo}'>
						<img border="0" src="/_styles/skin/search_results_next.gif" />
					</a>
				</xsl:if>
			</xsl:when>

			<xsl:otherwise>
				<xsl:variable name="pend" select="$total" />

				<!-- call paging template here -->
				<xsl:call-template name="paging">
					<xsl:with-param name="perPage" select="$perPage" />
					<xsl:with-param name="counter" select="$pstart" />
					<xsl:with-param name="current" select="$current" />
					<xsl:with-param name="total" select="$pend" />
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<!--****************************************************************************-->







	<!-- 4. DISPLAYSRESULTS TEMPLATE DECLARATION************************************-->
	<xsl:template name="displayResults">
		<xsl:for-each select="queryResult/results/result">
			<div class="search_result_item">

				<h4>
					<xsl:value-of select="title" />
				</h4>

				<div class="search_result_item_content">
					<ul class="search_result_buttons">
						<li class="get_content">
							<a href="http://hdl.handle.net/{contentIdentifier}" target="_blank">
								<img src="/_styles/skin/btn_getcontent.gif" alt="Get Content" />
							</a>
						</li>
						<li class="view_metadata">
							<a href="javascript: openPopupWindow('/training/search/metadata.jsp?minsidentifier={metadataInstanceIdentifier}&amp;objidentifier={contentIdentifier}')">
								<img src="/_styles/skin/btn_viewmetadata.gif" alt="View Metadata" />
							</a>
						</li>
					</ul>
					<!-- END .search_result_buttons -->


					<p>
						<xsl:value-of select="description" />
					</p>

					<p>
						<em>Content Object ID:</em>
						<xsl:value-of select="contentIdentifier" />
					</p>

					<p>
						<em>Metadata Instance ID:</em>
						<xsl:value-of select="metadataInstanceIdentifier" />
					</p>
				</div>
				<!-- END .search_result_item_content -->
			</div>
			<!-- END .search_result_item -->
		</xsl:for-each>
	</xsl:template>
	<!--***********************************************************************************-->


	<!-- START PROCESSING FROM ROOT NODE -->
	<xsl:template match="/">

		<!--***********************BEGIN DISPLAY OF MAIN HEADER*************************-->
		<xsl:call-template name="displayHeader" />
		<!--****************************************************************************-->


		<!--***********************BEGIN PAGING NAVIGATION HEADER***********************-->
		<p id="search_results_nav">
			<xsl:call-template name="displayPagingStruct" />
		</p>
		<!--****************************************************************************-->


		<!--***********************DISPLAY RESULTS**************************************-->
		<xsl:call-template name="displayResults" />
		<!--****************************************************************************-->


		<!--***********************DISPLAY PAGING NAVIGATION HEADER********************-->
		<p class="search_results_nav">
			<xsl:call-template name="displayPagingStruct" />
		</p>
		<!--***************************************************************************-->

	</xsl:template>
</xsl:stylesheet>